const app = getApp();

Page({
	data: {
    user:{},
		StatusBar: app.globalData.StatusBar,
		CustomBar: app.globalData.CustomBar,
		TabbarBot: app.globalData.tabbar_bottom,
		hidden: true,
		region: ['重庆市', '重庆市', '江北区'],
	},
	onLoad: function (option) {
    const _this = this
	    wx.getSetting({
	        success: res => {
		        if (!res.authSetting['scope.userInfo']) {
		            wx.redirectTo({
		              	url: '/pages/auth/auth'
		            })
		        }
	        }
      });
      wx.getStorage({
        key: 'user',
        success: function (res) {
          _this.setData({
            user: res.data
          })
        }
      });
	},
	RegionChange: function (e) {
		this.setData({
			region: e.detail.value
		})
  },
  add:function(e){
    let isDefault = ''
    if (e.detail.value.isDefault) {
      isDefault = 1
    }else{
      isDefault = 0
    }
    wx.request({
      method:"POST",
      url: 'http://localhost:8989/address',
      data:{
        uid: this.data.user.uid,
        name: e.detail.value.name,
        provinceName: e.detail.value.city[0],
        cityName: e.detail.value.city[1],
        areaName: e.detail.value.city[2],
        isDefault: isDefault,
        phone: e.detail.value.phone,
        address: e.detail.value.address
      },
      success:(res)=>{
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 2000//持续的时间
        })
        wx.navigateTo({
          url: '/pages/user/address/index',
        })
      }
    })
  },
  reset:function(e){
    console.log("清空")
  }
	
});
